<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../vue.js"></script>
    <script>
        Vue.config.productionTip = false
        let data = {
            name: '尚硅谷',
            adress: '北京'
        }
        /*    Object.defineProperty(data,'name',{
               get()
               {
                   return data.name
               },
               set(val)
               {
                   data.name=val
               }
           }) */

        let vn={}
        vm._data=data=obs
        
        const obs = new Observer(data)
        console.log(obs);
        function Observer(obj) {
            //汇总对象中的所有属性形成一个数组  这样的方式并没有递归 只有第一层的
            const keys = Object.keys(obj)
            keys.forEach((k) => {
                Object.defineProperty(this, k, {
                    get() {
                        return obj[k]
                    },
                    set(val) {
                        obj[k] = val
                    }
                })
            })
        }
    </script>
</body>

</html>